//
//  TTJumpManager.m
//  PPDL
//
//  Created by 王洋 on 2019/7/27.
//  Copyright © 2019 王洋. All rights reserved.
//

#import "TTJumpManager.h"
#import "PPTabBarController.h"
#import "PPWebViewController.h"
#import "GoodDetailViewController.h"
#import "PaingSocketViewController.h"
#import "OrderDetailViewController.h"
#import "PPCouponViewController.h"

@implementation TTJumpManager

+ (instancetype)share {
    
    static TTJumpManager* helper = nil;
    static dispatch_once_t onceToken;
    
    dispatch_once(&onceToken, ^{
        if (!helper) {
            helper = [[self alloc] init];
        }
    });
    return helper;
}

- (void)pushViewControllerWithModel:(PP_jumpModel *)model {
    
    switch (model.type) {
        case CommentClickType_UnKnow:
        {

        } break;
            
        case CommentClickType_Home:
        {
            
            UINavigationController *navi = (UINavigationController *)[PPTabBarController shareTabbar].selectedViewController;
            if (navi.viewControllers.count > 1) {
                
                [(UINavigationController *)[PPTabBarController shareTabbar].selectedViewController popViewControllerAnimated:NO];
            }
            
            [PPTabBarController setCurrentIndex:PPTabbarIndexTypeHome];
            
        }break;
            
        case CommentClickType_Auction:
        {
            UINavigationController *navi = (UINavigationController *)[PPTabBarController shareTabbar].selectedViewController;
            if (navi.viewControllers.count > 1) {
                
                [(UINavigationController *)[PPTabBarController shareTabbar].selectedViewController popViewControllerAnimated:NO];
            }
            
            [PPTabBarController setCurrentIndex:PPTabbarIndexTypeAuction];
            
        }break;
            
            case CommentClickType_Shop:
            {
                UINavigationController *navi = (UINavigationController *)[PPTabBarController shareTabbar].selectedViewController;
                if (navi.viewControllers.count > 1) {
                    
                    [(UINavigationController *)[PPTabBarController shareTabbar].selectedViewController popViewControllerAnimated:NO];
                }
                
                [PPTabBarController setCurrentIndex:PPTabbarIndexTypeShop];
                
            }break;
            
        case CommentClickType_Income:
        {
            
            UINavigationController *navi = (UINavigationController *)[PPTabBarController shareTabbar].selectedViewController;
            if (navi.viewControllers.count > 1) {
                
                [(UINavigationController *)[PPTabBarController shareTabbar].selectedViewController popViewControllerAnimated:NO];
            }
            
            [PPTabBarController setCurrentIndex:PPTabbarIndexTypeIncome];
            
        }break;
            
        case CommentClickType_Mine:
        {
            UINavigationController *navi = (UINavigationController *)[PPTabBarController shareTabbar].selectedViewController;
            if (navi.viewControllers.count > 1) {
                
                [(UINavigationController *)[PPTabBarController shareTabbar].selectedViewController popViewControllerAnimated:NO];
            }
            
            [PPTabBarController setCurrentIndex:PPTabbarIndexTypeMine];
            
        }break;
            
        case CommentClickType_HtmlPage:
        {
            
            if ([model.ID isKindOfClass:[NSString class]] && model.ID.length > 0) {
                PPWebViewController *VC = [[PPWebViewController alloc]init];
                
                if ([model.ID hasPrefix:@"http"]) {
                    VC.webUrl = model.ID;
                } else {
                    VC.webUrl = [NSString stringWithFormat:@"http://%@",model.ID];
                }
                [(UINavigationController *)[PPTabBarController shareTabbar].selectedViewController pushViewController:VC animated:YES];
                
            } else {
                
                return;
            }

        }break;
            
        case CommentClickType_PhoneCall:
        {
            
            [Utilities callPhone:model.ID];
            
        } break;

            
        // ------------------------订单消息相关------------------------
        case CommentClickType_OrderMsg: {
            
            
        } break;
            
        // ------------------------系统消息相关------------------------
        case CommentClickType_SystemMsg: {
            
            
        } break;
            
        // ------------------------活动相关------------------------
        case CommentClickType_CouponList: {//优惠券列表
            
            PPCouponViewController *VC = [[PPCouponViewController alloc] init];
            [(UINavigationController *)[PPTabBarController shareTabbar].selectedViewController pushViewController:VC animated:YES];
            
        } break;
            
        // ------------------------各类详情------------------------
        case CommentClickType_GoodsDetail:
        {
            GoodDetailViewController *VC = [[GoodDetailViewController alloc] init];
            VC.goodsID = model.ID;
            VC.type = (PPGoodDetailType)[[model.ext valueForKey:@"goodDetailType"] integerValue];
            [(UINavigationController *)[PPTabBarController shareTabbar].selectedViewController pushViewController:VC animated:YES];

        }break;

        case CommentClickType_InAuctionDetail: {
            
//            PaingSocketViewController *VC = [[PaingSocketViewController alloc] init];
////            VC.goodsID = model.ID;
//            [(UINavigationController *)[PPTabBarController shareTabbar].selectedViewController pushViewController:VC animated:YES];
            
        } break;
            
        case CommentClickType_OrderDetail: {
            
            OrderDetailViewController *VC = [[OrderDetailViewController alloc] init];
            VC.orderID = model.ID;
            [(UINavigationController *)[PPTabBarController shareTabbar].selectedViewController pushViewController:VC animated:YES];
            
        } break;
            
        default:
        {
            //            [[Utility sharedUtility] showToastMessage:@"当前版本过低，请升级最新版本..." messageType:MessageTypeInfo];

        }break;

    }
}

/*
 * 用于固定页面的跳转，不带参数
 */
- (void)pushViewControllerWithClassName:(NSString *)name {
    
    if (name.length) {
        
        Class cls = NSClassFromString(name);
        UIViewController *vc = [[cls alloc] init];
        [(UINavigationController *)[PPTabBarController shareTabbar].selectedViewController pushViewController:vc animated:YES];
        
    } else {
        
    }
}

@end
